<div class="fsh-pop">
    <div id="add_form" class="layui-form">
        <input name="parent_id" type="hidden" value="<%=parent_id%>">
        <input name="course_id" type="hidden" value="<%=course_id%>">
        <input name="hash" type="hidden" value="<%=hash%>">
        <div class="layui-form-item">
            <label class="layui-form-label">课程封面</label>
            <div class="layui-input-block">
                <img class="layui-upload-img" id="upload_header" src="<%=img_url%>">
                <input name="img_url" type="hidden" id="cover">
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label"><i>*</i>课程分类</label>
            <div class="layui-input-block">
                <input lay-verify="required" autocomplete="off" placeholder="请选择课程分类"
                       class="layui-input" id="category_title" value="<%=major_name%>">
                <input name="major_id" type="hidden" id="major_id" value="<%=major_id%>">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label"><i>*</i>课程名称</label>
            <div class="layui-input-block">
                <input type="text" name="course_task" lay-verify="required" placeholder="请输入内容" class="layui-input" value="<%=course_task%>">
            </div>
        </div>

<!--        <div class="layui-form-item">-->
<!--            <label class="layui-form-label"><i>*</i>主讲老师</label>-->
<!--            <div class="layui-input-block">-->
<!--                <select id="teacher" lay-filter="status" name="course_teacher_id" value="<%=course_teacher_id%>">-->
<!--                    <option value="1">张老师</option>-->
<!--                    <option value="2">李老师</option>-->
<!--                    <option value="3">王老师</option>-->
<!--                </select>-->
<!--            </div>-->
<!--        </div>-->

<!--        <div class="layui-form-item">-->
<!--            <label class="layui-form-label"><i>*</i>课程状态</label>-->
<!--            <div class="layui-input-block">-->
<!--                <select id="status" lay-filter="status" name="course_state" value="<%=status%>">>-->
<!--                    <option value="0">未直播</option>-->
<!--                    <option value="1">直播中</option>-->
<!--                    <option value="2">录播</option>-->
<!--                    <option value="3">其他资源</option>-->
<!--                </select>-->
<!--            </div>-->
<!--        </div>-->

        <div class="layui-form-item">
            <label class="layui-form-label"><i>*</i>课程难度</label>
            <div class="layui-input-block">
                <select id="easy" lay-filter="easy" name="ease" value="<%=easy%>">>
                    <option value="0">初级</option>
                    <option value="1">中级</option>
                    <option value="2">高级</option>
                </select>
            </div>
        </div>

        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">是否必修课</label>
            <div class="layui-input-block">
                <input type="checkbox" lay-skin="switch" lay-text="ON|OFF" lay-filter="switchTest" id="switchTest">
                <input name="course_subject" type="hidden" id="subject" value="<%=course_subject%>">
            </div>
        </div>

<!--        <div class="layui-form-item">-->
<!--            <label class="layui-form-label">开始时间</label>-->
<!--            <div class="layui-input-block">-->
<!--                <input type="text" name="startTime" id="startDate" lay-verify="datetime" placeholder="请选择课程开始时间"-->
<!--                       autocomplete="off" class="layui-input" value="<%=startTime%>">-->
<!--            </div>-->
<!--        </div>-->
<!--        <div class="layui-form-item">-->
<!--            <label class="layui-form-label">结束时间</label>-->
<!--            <div class="layui-input-block">-->
<!--                <input type="text" name="endTime" id="endingDate" lay-verify="datetime" placeholder="请选择课程结束时间"-->
<!--                       autocomplete="off" class="layui-input" value="<%=endTime%>">-->
<!--            </div>-->
<!--        </div>-->
    </div>

</div>
<style type="text/css">
    #upload_header {
        width: 200px;
        height: 100px;
        border: 1px solid #e3e3e3;
    }
</style>
<script type="text/javascript">


    layui.use(['upload', 'form', 'laydate'], function () {
        var upload = layui.upload;
        var form = layui.form;
        var layDate = layui.laydate;
        //是否必修课
        var checked = $('#subject').val()==1;
        $('#switchTest').prop('checked',checked);
        form.on('switch(switchTest)', function (data) {
            $("#subject").val(this.checked ? 1 : 0);
        });
        //主讲老师
        form.on('select(teacher)', function (data) {


        });
        //难易程度
        form.on('select(easy)', function (data) {

        });
        // 课程状态
        form.on('select(status)', function (data) {

        });

        var parentId = '';
        $("#category_title").click(function () {
            showDialog({
                title: '选择父级菜单'
                , template: 'views/category/template/menu.html'
                , width: 400
                , height: 600
                , yes: function (index, layero) {
                    var res = callbackdata();
                    layer.close(index);
                    parentId = res.key;
                    $("#category_title").val(res.title);
                    $("#major_id").val(parentId);

                }

            });

        });
        //执行实例
        var uploadInst = upload.render({
            elem: '#upload_header'
            , url: context + '/api/fileupload/add'
            , field: 'attach'
            , done: function (res) {
                //如果上传失败
                if (res.success) {
                    $('#upload_header').attr('src', res.link);
                    $('#cover').val(res.link);
                } else {
                    layui.layer.msg('上传失败');
                }
                //上传成功
            }
            , error: function () {
                //演示失败状态，并实现重传
                var demoText = $('#demoText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function () {
                    uploadInst.upload();
                });
            }
        });

        //开始日期
        layDate.render({
            elem: '#startDate'
            , type: 'datetime'
        });
        //结束日期
        layDate.render({
            elem: '#endingDate'
            , type: 'datetime'
        });

    });

</script>
